package org.chuanyang.mm;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CategoryAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<String> data;
	private int layout;
	public CategoryAdapter(Context context, List<String> data, int layout) {
		this.data = data;
		this.layout = layout;
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		TextView tv;
		if (convertView == null) {
			tv = (TextView) mInflater.inflate(
					layout, parent, false);
		} else {
			tv = (TextView) convertView;
		}

		tv.setText(data.get(position));
		return tv;
	}

}
